package org.wzq.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

/**
 * project:
 * author: wzq
 * date: 2014/8/8
 * description:
 */
public class GeneralUtils {
    private static Context sCtx;

    public static void injectContext(Context ctx) {
        sCtx = ctx;
    }

    public static String getPkgName() {
        return sCtx.getPackageName();
    }

    public static String getVersionName() {
        PackageManager pm = sCtx.getPackageManager();
        PackageInfo pi;
        try {
            pi = pm.getPackageInfo(sCtx.getPackageName(), 0);
            return pi.versionName;
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return "";
    }

    public static int getVersionCode() {
        PackageManager pm = sCtx.getPackageManager();
        PackageInfo pi;
        try {
            pi = pm.getPackageInfo(sCtx.getPackageName(), 0);
            return pi.versionCode;
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return 0;
    }
}
